package test1;

import java.util.Comparator;
import java.util.TreeMap;

public class test2 {
    //统计字符串的次数
    public static void main(String[] args) {
        String str="skdjfsklfjkabcdjf";
        TreeMap<Character,Integer> tm=new TreeMap<>(new Comparator<Character>() {
            @Override
            public int compare(Character o1, Character o2) {
                return o1-o2;
            }
        });

        for (int i = 0; i < str.length(); i++) {
            char c = str.charAt(i);
            if(tm.containsKey(c)){
                Integer value = tm.get(c);
                value++;
                tm.put(c,value);
            }
            else{
                tm.put(c,1);
            }
        }

        System.out.println(tm);
    }
}
